package com.gateway.server.helper;

import com.gateway.register.common.dto.MetaDataRegisterDTO;
import com.gateway.repository.bean.GatewayApiMetaData;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: ahcloud-gateway
 * @description: 网关接口元数据
 * @author: YuKai Fan
 * @create: 2023/5/29 16:41
 **/
public class GatewayApiMetadataHelper {

    /**
     * 数据转换
     * @param dto
     * @return
     */
    public static GatewayApiMetaData convert(MetaDataRegisterDTO dto) {
        GatewayApiMetaData gatewayApiMetaData = new GatewayApiMetaData();
        gatewayApiMetaData.setApiPath(dto.getApiPath());
        gatewayApiMetaData.setAddPrefixed(dto.getAddPrefixed() ? 1 : 0);
        gatewayApiMetaData.setAppId(dto.getAppId());
        gatewayApiMetaData.setAppName(dto.getAppName());
        gatewayApiMetaData.setConsume(dto.getConsume());
        gatewayApiMetaData.setProduce(dto.getProduce());
        gatewayApiMetaData.setEnv(dto.getEnv());
        gatewayApiMetaData.setDescription(dto.getDesc());
        gatewayApiMetaData.setHttpMethod(dto.getApiHttpMethodEnum().getName());
        gatewayApiMetaData.setMethodName(dto.getMethodName());
        gatewayApiMetaData.setQualifiedName(dto.getQualifiedName());
        gatewayApiMetaData.setRpcType(dto.getRpcType());
        gatewayApiMetaData.setServiceId(dto.getServiceId());
        gatewayApiMetaData.setCreator("SYSTEM");
        gatewayApiMetaData.setModifier("SYSTEM");
        return gatewayApiMetaData;
    }
}
